<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增录播记录')" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
    <th:block th:include="include :: summernote-css" />

</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-recoring-add">
            <input type="hidden" name="coverImg">
            <input type="hidden" name="mediaUrl">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">标题：</label>
                <div class="col-sm-8">
                    <input name="name" class="form-control" type="text" required>
                </div>
            </div>
            <!--<div class="form-group">
                <label class="col-sm-3 control-label">关联直播间：</label>
                <div class="col-sm-8">
                    <input name="roomid" class="form-control" type="text">
                </div>
            </div>-->
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">封面展示图：</label>
                <div class="col-sm-8">
                    <input id="coverImg" name="file" type="file">
                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i>尺寸比例：16:9</span>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">录播视频：</label>
                <div class="col-sm-8">
                    <input id="mediaUrl" name="file" type="file">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">简介：</label>
                <div class="col-sm-8">
                    <textarea name="synopsis" class="form-control" required></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">文案：</label>
                <div class="col-sm-8">
                    <input name="copywriting" type="hidden">
                    <div id="copywriting" ></div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js" />
    <th:block th:include="include :: summernote-js" />

    <script th:inline="javascript">
        var prefix = ctx + "tea/recoring"
        $("#form-recoring-add").validate({
            focusCleanup: true
        });

        // 单图上传
        $("#coverImg").fileinput({
            uploadUrl: ctx + 'common/upload',
            maxFileCount: 1,
            autoReplace: true,
            showPreview: false,
            showRemove: false
        }).on('fileuploaded', function (event, data, previewId, index) {
            var rsp = data.response;
            log.info("return url：" + rsp.url)
            log.info("reutrn fileName：" + rsp.fileName)
            log.info("reutrn newFileName：" + rsp.newFileName)
            log.info("return originalFilename：" + rsp.originalFilename)
            $("input[name='coverImg']").val(rsp.url)
        }).on('fileremoved', function (event, id, index) {
            $("input[name='" + event.currentTarget.id + "']").val('')
        })
        // 单图上传
        $("#mediaUrl").fileinput({
            uploadUrl: ctx + 'common/upload',
            maxFileCount: 1,
            autoReplace: true,
            showPreview: false,
            showRemove: false
        }).on('fileuploaded', function (event, data, previewId, index) {
            var rsp = data.response;
            log.info("return url：" + rsp.url)
            log.info("reutrn fileName：" + rsp.fileName)
            log.info("reutrn newFileName：" + rsp.newFileName)
            log.info("return originalFilename：" + rsp.originalFilename)
            $("input[name='mediaUrl']").val(rsp.url)
        }).on('fileremoved', function (event, id, index) {
            $("input[name='" + event.currentTarget.id + "']").val('')
        })

        $('#copywriting').summernote({
            lang: 'zh-CN',
            minHeight: "300px",
        });

        function submitHandler() {
            if( !$("input[name='coverImg']").val()){
                alert("请上传封面展示图")
                return
            }
            if( !$("input[name='mediaUrl']").val()){
                alert("请上传录播视频")
                return
            }
            $("input[name='copywriting']").val($('#copywriting').summernote('code'))
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-recoring-add').serialize());
            }
        }
    </script>
</body>
</html>